{literal}
<style type="text/css">
    .header {
        width: 100%;
        text-align: center;
        color: black;
        font-size: 24px;
        font-weight: bold;
        text-transform: uppercase;
    }
</style>

<script type="text/javascript">
$(document).ready(function() {
	registerLabServiceCode();
    $('#addLabBtn').bind('click', addLabItem);
    $('#ticketSelector').change(function() {
        $('.chi-dinh').hide();
        var value = $(this).val();
        $('#' + value).show();
    });
});   

function deleteLabItem(trId, labGroupId) {    
    $('tr#' + trId).remove();          
    
    var labGroup = $('#labItemListTbd tr[labgroup=' + labGroupId + ']');
    var rowspan = labGroup.find('td:first-child').attr('rowspan');
    labGroup.find('td:first-child').attr('rowspan', rowspan - 1)
}

function addLabItem() {
    var labCode = $('#labCode').val();
    var labName = $('#labName').val();

    if (labCode == '' || labName == '') {
    	var buttons = {};
        buttons[_('Close')] = function() {
            $(this).dialog('close');        
        };
    	generalDialog(null, 'Lỗi', 'Nhập mã/tên xét nghiệm', null,{
            autoOpen: true,         
            bgiframe: true,
            resizable: false,       
            width: 350,
            height: 120,
            modal: true,
            buttons: buttons,
            dialogClass: 'custom-dialog'                    
        },_('Close'));
        return;
    }
    
    var labGroupId = $('#labGroupId').val();
    var labGroupName = $('#labGroupName').val();

    var labGroupTR = $('#labItemListTbd tr[labgroup=' + labGroupId + ']').length;

    var currentNumTR = $('#labItemListTbd tr').length;
    
    // Lab group is not initialized
    if (labGroupTR == 0) {      	      
        var id = currentNumTR + 2; 
    	var tr = 
         '<tr labgroup="' + labGroupId + '">' +
            '<td rowspan="2" style="width: 120px; font-weight: bold;">' +
                '<div style="white-space: normal;">' + labGroupName + '</div>' +
            '</td>' +
            '<td style="width: 90px;"> </td>' +
            '<td style="width: 250px;"> </td>' +
            '<td class="last"> </td>' + 
        '</tr>' +
        '<tr id="' + id + '">' +            
            '<td style="width: 90px;">' + labCode + '</td>' +
            '<td style="width: 250px;">' + labName + '</td>' +
            '<td class="last">' +
                '<a href="javascript:deleteLabItem(' + id + ',' + labGroupId + ')">' +
                    '<img src="../images/remove_small_16x16.png"/>' + 
                '</a>' +
                '<input type="hidden" name="labgroup' + labGroupId + '[' + id + ']" value="' + labName + '"/>' +
            '</td>' + 
        '</tr>';
        $('#labItemListTbd').append(tr);
    } else {
    	var id = currentNumTR + 1; 
    	var trObj = $('#labItemListTbd tr[labgroup=' + labGroupId + ']');
        var rowspan = trObj.find('td:first-child').attr('rowspan');
        trObj.find('td:first-child').attr('rowspan', rowspan + 1);

        var tr =
            '<tr id="' + id + '">' +  
                '<td style="width: 90px;">' + labCode + '</td>' +
                '<td style="width: 250px;">' + labName + '</td>' +
                '<td class="last">' +
                    '<a href="javascript:deleteLabItem(' + id + ',' + labGroupId + ')">' +
                        '<img src="../images/remove_small_16x16.png"/>' + 
                    '</a>' +
                    '<input type="hidden" name="labgroup' + labGroupId + '[' + id + ']" value="' + labName + '"/>' +
                '</td>' + 
            '</tr>'; 
        trObj.after(tr);
    }
    resetForm();
}

function resetForm() {
	var labCode = $('#labCode').val('');
    var labName = $('#labName').val('');
    var labGroupId = $('#labGroupId').val('');
    var labGroupName = $('#labGroupName').val('');

    labCode.focus();  
}

function registerLabServiceCode() {
    // Autocomplete for Service Code    
    $('#labCode').flushCache();                
    var codeAC = $('#labCode').autocomplete('../CanLamSang/GetLabCodeAutocompleteAjax?set_ajax_view');
    codeAC.setOptions({
        width:          255,
        minChars:       1,     
        matchContains:  true,                                      
        formatItem:     labFormatMatch                                                                
    });

    // Autocomplete for Service Name    
    $('#labName').flushCache();                
    var codeAC = $('#labName').autocomplete('../CanLamSang/GetLabNameAutocompleteAjax?set_ajax_view');
    codeAC.setOptions({
        width:          255,
        minChars:       1,     
        matchContains:  true,                                      
        formatItem:     labFormatMatch                                                                
    });
}

//Fill data for service code autocomplete result
$('#labCode').result(function(event, data, formatted) {
    $(this).val(data[0]);
    $('#labName').val(data[1]);
    $('#labGroupId').val(data[3]);
    $('#labGroupName').val(data[4]);
    
    $('#addLabBtn').focus();      
});

//Fill data for service code autocomplete result
$('#labName').result(function(event, data, formatted) {
    $(this).val(data[1]);
    $('#labCode').val(data[0]);
    $('#labGroupId').val(data[3]);
    $('#labGroupName').val(data[4]);
    
    $('#addLabBtn').focus();      
});

// Format data result for service code autocomplete
function labFormatMatch(item) {        
    return item[0] + '<br />' + item[1];
}
</script>
{/literal}

<div style='padding: 0px 0px;'>                                                         
    <div class='field-row add-patient-row'>                
        <div class='field-label add-patient-label' style='width: 120px;'>Chọn phiếu</div>
        <div class='field-value add-patient-value' style='width: 350px;'>
             <select id="ticketSelector" style='width: 200px;'>
                <option value='0' selected="selected">-- Chọn phiếu --</option>
                <option value='dien-co'>Điện cơ</option>
                <option value='dien-nao'>Điện não</option>
                <option value='sieu-am'>Siêu âm</option>
                <option value='xet-nghiem'>Xét nghiệm</option>
                <option value='chuyen-khoa'>Khám chuyên khoa</option>
                <option value='chi-dinh-khac'>Chỉ định khác</option>
             </select>&nbsp;                               
        </div>                                                                          
       <div style='clear: both;'></div>
    </div>                       
</div> 
 
<!-- DIEN CO --> 
<div class='chi-dinh' id="dien-co" style='padding: 0px 0px; display: none;'>                                                         
    <div class='field-row add-patient-row'>                
        <div class='header field-label add-patient-label'>Phiếu đo điện cơ</div>                                                                                
       <div style='clear: both;'></div>
    </div>       
    
    <form id="formDienCo">
        <div class='field-row add-patient-row'>                
            <div class='field-label add-patient-label' style='width: 120px;'>Bác sĩ</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>
                 <input type='text' name='data[doctor]' style='width: 300px;' value='{$doctor}'/> &nbsp;             
            </div>                                                                                               
            <div style='clear: both;'></div>
        </div>
        
         <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>Chẩn đoán</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>                 
                 <textarea name="data[diagnosis]" style="width: 300px;" rows="1">{$diagnosis}</textarea>&nbsp;             
            </div>            
            <div style='clear: both;'></div>
        </div> 
        
        <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>Yêu cầu</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>
                 <textarea name="data[request]" style="width: 300px;" rows="1"></textarea>&nbsp;             
            </div>
            <div style='clear: both;'></div>
        </div>                 
    </form>   
    
    <div style="margin-top: 20px; text-align: right; margin-right: 80px;">        
        <input type="button" id="btnSave" style="width: 100px;" onclick="javascript:printPhieuDienCo();" value="In"></input>                                                   
    </div>                
</div> 


<!-- DIEN NAO --> 
<div class='chi-dinh' id='dien-nao' style='padding: 0px 0px; display: none;'>                                                         
    <div class='field-row add-patient-row'>                
        <div class='header field-label add-patient-label'>Phiếu đo điện não</div>                                                                                
       <div style='clear: both;'></div>
    </div>       
    
    <form id="formDienNao">
        <div class='field-row add-patient-row'>                
            <div class='field-label add-patient-label' style='width: 120px;'>Bác sĩ</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>
                 <input type='text' name='data[doctor]' style='width: 300px;' value='{$doctor}'/> &nbsp;             
            </div>                                                                                               
            <div style='clear: both;'></div>
        </div>
        
         <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>Chẩn đoán</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>                 
                 <textarea name="data[diagnosis]" style="width: 300px;" rows="1">{$diagnosis}</textarea>&nbsp;             
            </div>            
            <div style='clear: both;'></div>
        </div> 
        
        <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>Yêu cầu</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>
                 <textarea name="data[request]" style="width: 300px;" rows="1"></textarea>&nbsp;             
            </div>
            <div style='clear: both;'></div>
        </div>                 
    </form>   
    
    <div style="margin-top: 20px; text-align: right; margin-right: 80px;">        
        <input type="button" id="btnSave" style="width: 100px;" onclick="javascript:printPhieuDienNao();" value="In"></input>                                                   
    </div>                
</div>



<!-- SIEU AM --> 
<div class='chi-dinh' id='sieu-am' style='padding: 0px 0px; display: none;'>                                                         
    <div class='field-row add-patient-row'>                
        <div class='header field-label add-patient-label'>Phiếu chỉ định siêu âm</div>                                                                                
       <div style='clear: both;'></div>
    </div>       
    
    <form id="formSieuAm">
        <div class='field-row add-patient-row'>                
            <div class='field-label add-patient-label' style='width: 120px;'>Bác sĩ</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>
                 <input type='text' name='data[doctor]' style='width: 300px;' value='{$doctor}'/> &nbsp;             
            </div>                                                                                        
            <div style='clear: both;'></div>
        </div>
        
        <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>Chẩn đoán</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>                 
                 <textarea name="data[diagnosis]" style="width: 300px;" rows="1">{$diagnosis}</textarea>&nbsp;             
            </div>            
            <div style='clear: both;'></div>
        </div> 
        
        <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>Chỉ định siêu âm</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>
                 <textarea name="data[request]" style="width: 300px;" rows="1"></textarea>&nbsp;             
            </div>
            <div style='clear: both;'></div>
        </div>   
        
        <div class='field-row add-patient-row'>                              
            <div class='field-value add-patient-value' style='width: 30px; padding-left: 120px;'>
                 <input id='bung_tong_quat' type="checkbox" name='data[bung_tong_quat]' />
                 &nbsp;             
            </div>
            <div class='field-label add-patient-label' style='width: 200px; text-align: left;'>
                <label for="bung_tong_quat" style="cursor: pointer;">1. Bụng tổng quát</label>
            </div>                                                                                            
            
            <div class='field-value add-patient-value' style='width: 30px;'>
                 <input id='tuyen_giap' type="checkbox" name='data[tuyen_giap]' />
                 &nbsp;             
            </div>   
            <div class='field-label add-patient-label' style='width: 200px; text-align: left;' >
                <label for="tuyen_giap" style="cursor: pointer;">4. Siêu âm tuyến giáp</label>
            </div>         
                                                                                                        
                                   
            <div style='clear: both;'></div>
        </div>  
        
        <div class='field-row add-patient-row'>                              
            <div class='field-value add-patient-value' style='width: 30px; padding-left: 120px;'>
                 <input id='dau_do' type="checkbox" name='data[dau_do]' />
                 &nbsp;             
            </div>
            <div class='field-label add-patient-label' style='width: 200px; text-align: left;'>
            <label for="dau_do" style="cursor: pointer;">2. Siêu âm đầu dò</label>
            </div>                                                                                                        
            
            <div class='field-value add-patient-value' style='width: 30px;'>
                 <input id='tim_doppler_mau' type="checkbox" name='data[tim_doppler_mau]' />
                 &nbsp;             
            </div>
            <div class='field-label add-patient-label' style='width: 200px; text-align: left;'>
                <label for="tim_doppler_mau" style="cursor: pointer;">5. Siêu âm tim doppler màu</label>
            </div>                                                                                                                               
            <div style='clear: both;'></div>
        </div> 
        
        
        <div class='field-row add-patient-row'>                              
            <div class='field-value add-patient-value' style='width: 30px; padding-left: 120px;'>
                 <input id="tuyen_vu" type="checkbox" name='data[tuyen_vu]' />
                 &nbsp;             
            </div>
            <div class='field-label add-patient-label' style='width: 200px; text-align: left;' >
                <label for="tuyen_vu" style="cursor: pointer;">3. Siêu âm tuyến vú</label>
            </div>                                                                                                                                         
            <div style='clear: both;'></div>
        </div>
         
                      
    </form>   
    
    <div style="margin-top: 20px; text-align: right; margin-right: 80px;">        
        <input type="button" id="btnSave" style="width: 100px;" onclick="javascript:printPhieuSieuAm();" value="In"></input>                                                   
    </div>                
</div>



<!-- XET NGHIEM --> 
<div class='chi-dinh' id='xet-nghiem' style='padding: 0px 0px; display: none;'>                                                         
    <div class='field-row add-patient-row'>                
        <div class='header field-label add-patient-label'>Phiếu chỉ định xét nghiệm</div>                                                                                
       <div style='clear: both;'></div>
    </div>       
    
    <form id="formXetNghiem">
        <div class='field-row add-patient-row'>                
            <div class='field-label add-patient-label' style='width: 120px;'>Bác sĩ</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 250px;'>
                 <input type='text' name='data[doctor]' style='width: 240px;' value='{$doctor}'/> &nbsp;             
            </div>                                                                                               
            <div style='clear: both;'></div>
        </div>
        
        <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>Chẩn đoán</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>                 
                 <textarea name="data[diagnosis]" style="width: 300px;" rows="1">{$diagnosis}</textarea>&nbsp;             
            </div>            
            <div style='clear: both;'></div>
        </div> 
        
        <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>XN khác</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>
                 <textarea name="data[request]" style="width: 300px;" rows="1"></textarea>&nbsp;             
            </div>
            <div style='clear: both;'></div>
        </div>                                 
      
    
        <div class="lab_grid" style="margin-top: 5px;">
            <!-- Heading -->
            <div class="h_div" style="border-left: 0; border-right: 0;">
                <table width="100%" cellpadding="0" cellspacing="0" >
                    <thead>
                        <tr>                                        
                            <th style="width: 120px;">{translate}Service type{/translate}</th>
                            <th style="width: 90px;">{translate}Code{/translate}</th>
                            <th style="width: 250px;">{translate}Service{/translate}</th>                    
                            <th class="last">&nbsp;</th>  
                        </tr>
                    </thead>
                </table>
            </div>
            
            <!-- Adding service table -->        
            <div class="b_div" style="border-left: 0; border-right: 0;">            
                <table id="addLabTbl" cellspacing="0" cellpadding="0" border="0" style="width: 600px;">
                    <tbody> 
                       <tr>                              
                            <td style="width: 120px;">
                               &nbsp;
                            </td>                                     
                            <td style="width: 90px;">
                                <input id="labCode" name="serviceCode" type="text" value="" style="width: 80px; text-transform: uppercase;" maxlength="45">
                                <input id="labId" type="hidden" value="" name="labId"></input>
                                <input id="labGroupId" type="hidden"></input>
                                <input id="labGroupName" type="hidden"></input> 
                            </td>
                            <td style="width: 250px;">
                                <input id="labName" type="text" name="labName" style="width: 240px;" maxlength="255" onkeyup="return moveNext(event, 'addLabBtn')"></input>                       
                            </td>
                            
                            <td class="last action">
                                <div id="addLabBtnDiv">
                                    <input id="addLabBtn" type="button" value="{translate}Add{/translate}"></input>
                                </div>                                            
                                <div id="addLabLoader" style="display: none">
                                    <img src="../images/ajax-loader-small.gif">
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
                
            </div>
            
            <!-- Payment item table -->
            <div id="labItemListDiv" class="b_div" style="border-left: 0; border-right: 0; margin-top: 5px; max-height: 190px; border-color: #AAA; border-top: 1px solid #AAA; -moz-box-shadow: 0 0 3px #AAA; -webkit-box-shadow: 0 0 3px #AAA;">
                <table style="width: 600px;" cellpadding="0" cellspacing="0" id="labItemListTbl" border="0">
                    <tbody id="labItemListTbd">
                        
                    </tbody>
                </table>
            </div>       
        </div>
     </form>
    
    <div style="margin-top: 20px; text-align: right; margin-right: 80px;">        
        <input type="button" id="btnSave" style="width: 100px;" onclick="javascript:printPhieuXetNghiem();" value="In"></input>                                                   
    </div>                
</div>


<!-- CHUYEN KHOA --> 
<div class='chi-dinh' id='chuyen-khoa' style='padding: 0px 0px; display: none;'>                                                         
    <div class='field-row add-patient-row'>                
        <div class='header field-label add-patient-label'>Phiếu khám chuyên khoa</div>                                                                                
       <div style='clear: both;'></div>
    </div>       
    
    <form id="formChuyenKhoa">
        <div class='field-row add-patient-row'>                
            <div class='field-label add-patient-label' style='width: 120px;'>Bác sĩ</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>
                 <input type='text' name='data[doctor]' style='width: 300px;' value='{$doctor}'/> &nbsp;             
            </div>                                                                                               
            <div style='clear: both;'></div>
        </div>
        
         <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>Chẩn đoán</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>                 
                 <textarea name="data[diagnosis]" style="width: 300px;" rows="1">{$diagnosis}</textarea>&nbsp;             
            </div>            
            <div style='clear: both;'></div>
        </div> 
        
        <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>Yêu cầu</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>
                 <textarea name="data[request]" style="width: 300px;" rows="1"></textarea>&nbsp;             
            </div>
            <div style='clear: both;'></div>
        </div>                 
    </form>   
    
    <div style="margin-top: 20px; text-align: right; margin-right: 80px;">        
        <input type="button" id="btnSave" style="width: 100px;" onclick="javascript:printPhieuChuyenKhoa();" value="In"></input>                                                   
    </div>                
</div>




<!-- CHI DINH KHAC --> 
<div class='chi-dinh' id='chi-dinh-khac' style='padding: 0px 0px; display: none;'>                                                         
    <div class='field-row add-patient-row'>                
        <div class='header field-label add-patient-label'>Phiếu chỉ định</div>                                                                                
       <div style='clear: both;'></div>
    </div>       
    
    <form id="formChiDinh">
        <div class='field-row add-patient-row'>                
            <div class='field-label add-patient-label' style='width: 120px;'>Bác sĩ</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>
                 <input type='text' name='data[doctor]' style='width: 300px;' value='{$doctor}'/> &nbsp;             
            </div>                                                                                               
            <div style='clear: both;'></div>
        </div>
        
         <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>Chẩn đoán</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>                 
                 <textarea name="data[diagnosis]" style="width: 300px;" rows="1">{$diagnosis}</textarea>&nbsp;             
            </div>            
            <div style='clear: both;'></div>
        </div> 
        
        <div class='field-row add-patient-row'>                              
            <div class='field-label add-patient-label' style='width: 120px;'>Yêu cầu</div>                                                                                            
            <div class='field-value add-patient-value' style='width: 350px;'>
                 <textarea name="data[request]" style="width: 300px;" rows="1"></textarea>&nbsp;             
            </div>
            <div style='clear: both;'></div>
        </div>                 
    </form>   
    
    <div style="margin-top: 20px; text-align: right; margin-right: 80px;">        
        <input type="button" id="btnSave" style="width: 100px;" onclick="javascript:printPhieuChiDinh();" value="In"></input>                                                   
    </div>                
</div>